<template>
  <router-layout>
    <Nodata v-if="isNoData"></Nodata>
    <van-list class="content-list" v-else v-model="loading" :finished="finished" @load="onLoad" :offset="0">
      <van-cell v-for="it in dataList" :key="it.id" :border="false">
        <div class="content-box" @click="go_detail(it)">
          <van-row class="container-header" type="flex" justify="space-between">
            <van-col class="van-ellipsis">
              <h2 class="content-title one-txt-cut">{{ it.title }}</h2>
              <p style="color:#ccc">{{it.create_time}}</p>
            </van-col>
            <van-col>
              <div class="content-img" v-if="it.banner_path">
                <img :src="it.banner_path" width="100%" height="100%" alt>
              </div>
            </van-col>
          </van-row>
        </div>
      </van-cell>
    </van-list>
  </router-layout>
</template>
<script>
import Nodata from "../public/nodata/Nodata"; // 导入暂无数据组件
import { news_list } from "@/api/news";
export default {
  name: "component_name",
  components: { Nodata },
  data() {
    return {
      loading: false,
      isNoData: false,
      finished: false,
      dataList: [],
      listQuery: {
        current: 1,
        limit: 5,
        company_id: localStorage.getItem("companyId")
      },
    };
  },
  methods: {
    async initList() {
      this.listQuery.content_type = this.$route.query.content_type;
      let res = await news_list(this.listQuery);
      if (res.data.status == 100) {
        this.dataList = res.data.data.rows;
        if (!res.data.data.results) {
          this.isNoData = true;
        }
      }
      this.loading = false;
      if (res.data.data.results <= this.dataList.length) {
        this.finished = true;
      }
    },
    onLoad() {
      setTimeout(() => {
        this.listQuery.limit += 2;
        this.initList();
      }, 1000);
    },
    go_detail(item) {
      if (item.content_type == 1) {
        window.location.href = item.link_url;
      }
      if (item.content_type == 0) {
        this.$router.push({
          path: "/StudyDetail",
          query: {
            id: item.id
          }
        });
      }
    }
  },
  created() {
    this.initList();
  }
};
</script>
<style lang="scss" scoped>
@import "NewsHome";
.van-ellipsis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
</style>
